<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="/include/TagLib.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=gb18030">
		<meta name="save" content="history">
		<title>QQ邮箱 - 联系人</title>
		<link rel="stylesheet" type="text/css"
			href="<c:url value='index_files/comm20100f0f4f.css'/>">
		<link rel="stylesheet" type="text/css" href="<c:url value='index_files/getcss.css' />">
		<link rel="stylesheet" type="text/css"
			href="<c:url value='index_files/addr0dfb5a.css'/>">
		<link rel="stylesheet" type="text/css"
			href="<c:url value='index_files/mail_group_addr0de489.css'/>">
		<script language="javascript" src="<c:url value='/js/jquery-1.4.2.min.js' />"></script>
		<style>
.list_body {
	min-width: 780px;
}

.myleftbar {
	min-width: 560px;
	margin-right: 186px;
	margin-top: 10px;
	_margin-top: 0px;
	position: relative;
	_float: left;
	_margin-right: 0px;
	zoom: 1;
}

.mysidebar {
	position: relative;
	right: 0px;
	float: right;
	top: 5px;
	_top: 0px;
	padding: 10px 8px 20px 8px;
	width: 164px;
	height: auto;
}

.M_l {
	overflow: hidden;
}

.O,.M {
	clear: left;
}

.html,.body {
	_position: relative;
	_overflow-x: hidden;
}
.companyType{
	cursor:pointer;
}
.active{
	font-weight:bold;
}
</style>
<script type="text/javascript">
	var status = true;
	function create(){
		location.href="<c:url value='/intoCreateContact.do' />";
	}
	function createCompany(idCompanyType){
		location.href="<c:url value='/intoCreateCompany.do' />?idCompanyType="+idCompanyType;
	}
	function updateCompany(idCompany){
		location.href="<c:url value='/intoUpdateCompany.do' />?idCompany="+idCompany;
	}
	function deleteCompany(idCompany,companyName){
		if(confirm("确定要删除"+companyName+"吗？")){
			location.href="<c:url value='/deleteCompany.do' />?idCompany="+idCompany;
		}
	}
	function deleteContact(){
		var s = $("input[name='AddrID']:checked");
		var str = "";
		for(i=0;i<s.length;i++){
			str += $(s[i]).val()+",";
		}
		location.href="<c:url value='/deleteContact.do' />?idContactPersons="+str;
	}
	function write(){
		
	}
	function selectAll(flag){
		if(flag==10){
			flag = status;
			if(status){
				status = false;
			}else{
				status = true;
			}
		}
		if(flag){
			$("input[name='AddrID']").attr("checked","checked");
		}else{
			$("input[name='AddrID']").attr("checked","");
		}
	}
	function queryContact(){
		var str = $("#FilterStr").val();
		location.href="<c:url value='/queryContact.do' />?queryStr="+encodeURI(encodeURI(str));
	}
	//显示该类型下的公司
   function showCompany(idObj){
   		var status = $("."+idObj).css("display");
   		if(status=="none"){
   			$("."+idObj).show();
   		}else{
   			$("."+idObj).hide();
   		}
   }
   function activeSpan(obj){
	   $("span[class='active']").removeAttr("class");
	   $("#"+obj).addClass("active"); 
   }
   $(function($){
      var idCompanyType="c${idCompanyType}";
      var idCompany = "cp${idCompany}";
   	  showCompany(idCompanyType);
   	  activeSpan(idCompany);
   });
</script>
	</head>
	<body class="tbody" id="list" style="">
		<div class="list_body">
			<div class="txt_title" style="_width: 99%">
				<div
					style="float: right; margin-top: -5px; _margin-top: 0px; font: normal 12px Verdana;">
					<input id="FilterStr" name="FilterStr" type="text" value="${queryStr}" class="txt normal" style="width:123px;margin:0 4px 0 0;vertical-align:middle;">
					<input type="button" value="查找" class="wd1 normal btn btn_true"
						onClick="queryContact();"
						style="margin: 0; vertical-align: middle;">
				</div>
				<c:choose>
					<c:when test="${idCompany!=null&&idCompany!=''}">
						${companyName}
					</c:when>
					<c:otherwise>
						所有联系人&nbsp;
					</c:otherwise>
				</c:choose>
			</div>
			<div class="attbg mysidebar" style="">
				<c:forEach items="${tblCompanyTypesList}" var="type" varStatus="order">
				<div class="companyType bd b_size bold title_left" onclick="showCompany('c${type.IDCOMPANYTYPE}');">
					<div class="right f_size normal" style="margin: 2px 1px 0 0">
						<a href="javascript:createCompany(${type.IDCOMPANYTYPE});">新建公司</a>
					</div>
					<span>${type.COMPANYTYPENAME}</span>
				</div>
				<ul class="c${type.IDCOMPANYTYPE} grouplist addrtitle" style="display:none;">
					<c:forEach items="${tblCompaniesList}" var="company" >
					<c:if test="${type.IDCOMPANYTYPE==company.IDCOMPANYTYPE}">
					<li>
						<span id="cp${company.idCompany}"><a href="<c:url value='/contactList.do' />?idCompany=${company.idCompany}">${company.companyName}</a>&nbsp;</span>
					</li>
					</c:if>
					</c:forEach>
				</ul>
				</c:forEach>
			</div>
			<div class="myleftbar">
				<form name="frm" method="post" action="">
					<div class="toolbg toolbgline" style="line-height: 24px; zoom: 1;">
						<div class="right">
							共
							<b>${fn:length(tblContactPersonsList)}</b> 个联系人
						</div>
						<input type="button" class="wd1 btn btn_true" value="新建"
							onClick="create();">
						<c:if test="${idCompany!=null&&idCompany!=''}">
						<input type="button" class="wd2 btn btn_true" value="编辑公司"
							onClick="updateCompany('${idCompany}');">
						</c:if>
						<input type="button" class="btn_sepline"
							style="vertical-align: top; margin-top: 3px;">
						<!-- <input type="button" class="wd1 btn btn_true" value="写信"
							onClick="write();"> -->
						<c:if test="${idCompany!=null&&idCompany!=''}">
						<input type="button" class="wd2 btn btn_true" value="删除公司"
							onClick="deleteCompany('${idCompany}','${companyName}');">
						</c:if>
						<input type="button" class="wd2 btn btn_true" value="删除"
							onClick="deleteContact();">
						<div class="oneheight"></div>
					</div>
					<div class="O minwidth">
						<div class="t_c">
							<input type="checkbox"
								onClick="selectAll(10);">
						</div>
						<div class="t_n a_title">
							姓名&nbsp;
						</div>
						<div class="t_e a_title">
							Email 地址
						</div>
						<div class="t_r a_title">
							公司&nbsp;
						</div>
						<div class="t_e a_title">
							公司类型&nbsp;
						</div>
						<!---->
					</div>
					<c:forEach items="${tblContactPersonsList}" var="person">
					<div class="M" style="overflow: hidden;">
						<div id="InGroupCon" style="display: none"></div>
						<label class="M_c">
							<input id="${person.idContactPerson}" type="checkbox" name="AddrID" value="${person.idContactPerson}">
						</label>
						<div class="M_l"
							onclick="location.href='<c:url value='/intoUpdateContact.do' />?idContactPerson=${person.idContactPerson}'">
							<p class="L_n">
								<span >&nbsp;${person.firstName}${person.lastName}</span>
							</p>
							<p class="L_e">
								<span >${person.email}</span>
							</p>
							<p class="L_r">
								<span >${person.tblcompanies.companyName}</span>
							</p>
							<p class="L_e L_desc" title="">
								<span >
									<c:forEach items="${tblCompanyTypesList}" var="type" varStatus="order">
										<c:if test="${type.IDCOMPANYTYPE==person.tblcompanies.idCompanyType}">
											${type.COMPANYTYPENAME}
										</c:if>
									</c:forEach>
								</span>
							</p>
							<!-- <span></span> -->
						</div>
					</div>
					</c:forEach>
					<div class="list_btline">
						<div style="height: 24px; padding-top: 3px"
							class="f_size selbar_bt barspace2">
							<span class="addrtitle">选择：</span>
							<a href="javascript:selectAll(true);">全部</a> -
							<a href="javascript:selectAll(false);">无</a>
						</div>
					</div>
					<div class="toolbg toolbgline" style="line-height: 24px;">
						<div class="right">
							共
							<b>${fn:length(tblContactPersonsList)}</b> 个联系人
						</div>
						<input type="button" class="wd1 btn btn_true" value="新建"
							onClick="create();">
						<c:if test="${idCompany!=null&&idCompany!=''}">
						<input type="button" class="wd2 btn btn_true" value="编辑公司"
							onClick="updateCompany('${idCompany}');">
						</c:if>
						<input type="button" class="btn_sepline"
							style="vertical-align: top; margin-top: 3px;">
						<!-- <input type="button" class="wd1 btn btn_true" value="写信"
							onClick="write();"> -->
						<c:if test="${idCompany!=null&&idCompany!=''}">
						<input type="button" class="wd2 btn btn_true" value="删除公司"
							onClick="deleteCompany('${idCompany}','${companyName}');">
						</c:if>
						<input type="button" class="wd2 btn btn_true" value="删除"
							onClick="deleteContact();">
					</div>
				</form>
			</div>
		</div>
	</body>
</html>